﻿
@page "/gatewayconfig/driverdebug"
@namespace ThingsGateway.Gateway.Blazor
@using System.Linq.Expressions;
@using BlazorComponent;
@using Furion.DataValidation;
@using Mapster;
@using Masa.Blazor.Presets;
@using System.IO;
@using Masa.Blazor;
@using Microsoft.AspNetCore.Authorization;

@using ThingsGateway.Admin.Blazor;
@using ThingsGateway.Admin.Core;
@using ThingsGateway.Core.Extension
@using ThingsGateway.Gateway.Application


@attribute [Authorize]
@inherits BaseComponentBase
@inject UserResoures UserResoures
@attribute [RolePermission]


<MRow NoGutters>
    <MCol Md=@(_isShowTreeView?3:0)>
        <MSheet Show=_isShowTreeView Style=@($"height: calc(100vh - {BlazorAppService.DefaultHeight}px);border-radius:0px;")>
            <MCardTitle>
                <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="mx-2 my-1" @bind-Value="_searchName" Outlined Label=@typeof(Device).GetDescription(nameof(Device.PluginName)) />
             </MCardTitle>
             <MTreeview Style=@($"height: calc(100vh - {BlazorAppService.DefaultHeight+200}px);overflow-y:auto") Dense TItem="PluginOutput"
                        TKey="string" OpenOnClick ActiveChanged=@((async a=>
                       {
                       await GetDebugUIAsync(a?.FirstOrDefault());
                       }) )
                        Items="_driverPlugins"
                        ItemText="r=>r.Name" ItemChildren="r=>r.Children"
                        Search="@_searchName"
                       Activatable ItemKey=@(r=>r.FullName)>
                 <LabelContent>
                     <span title=@context.Item.Name>
                         @context.Item.Name
                    </span>
                </LabelContent>
                <LabelContent>
                    <span title=@context.Item.Name>
                        @context.Item.Name
                    </span>
                </LabelContent>
            </MTreeview>
        </MSheet>
    </MCol>
    <MCol Md=@(_isShowTreeView?9:12)>
        <MSheet Style=@($"height: calc(100vh - {BlazorAppService.DefaultHeight}px);border-radius:0px;")>
            <MToolbar  Elevation="0" Height="40" Rounded="false">
                    <MButton Class="mx-1" OnClick=@(() => _isShowTreeView=!_isShowTreeView) Color="primary" Icon>
                        <MIcon>mdi-menu</MIcon>
                    </MButton>
                    <MLabel>
                        @_importRef?.ToString()
                    </MLabel>
            </MToolbar>
            @if (_debugRender != null)
            {
                <MSheet Style=@($"height: calc(100vh - {BlazorAppService.DefaultHeight+50}px);border-radius:0px;")>
                @_debugRender
                </MSheet>
            }
        </MSheet>

    </MCol>

</MRow>


